package com.example.flo;

import ag.AGAnimation;
import ag.AGContext;
import ag.AGModel;
import ag.AGModelManager;
import ag.AGObject;
import ag.AGView;
import ag.IAGAnimationCompletedEventHandler;
import ag.ui.AGButton;
import ag.ui.AGControl;
import ag.ui.IAGEventHandler;
import android.graphics.PointF;
import android.graphics.RectF;

public class TestView1 extends AGView {

	private AGModel _model;
	private AGObject _object;
	private AGObject _object2;
	private AGObject _object3;
	
	private AGModel _model2;
	private AGObject _objBackground1;
	private AGObject _objBackground2;
	private AGObject _objBackground3;
	
	private AGButton _btnOK;
	private AGButton _btnSwitch;
	
	public TestView1() {
		super();
		// TODO Auto-generated constructor stub
		
		this._model2 = AGModelManager.getInstance().getModel(2);
		this._objBackground1 = AGObject.createObject(this._model2);
		this.addObject(this._objBackground1);
		this._objBackground1.setAction(0);
		this._objBackground1.setPosition(new PointF(0,0));
		this._objBackground1.setZIndex(988);
		
		this._model = AGModelManager.getInstance().getModel(1);
		this._object = AGObject.createObject(this._model);
		this.addObject(this._object);
		this._object.setPosition(new PointF(100,25));
		this._object.setZIndex(998);
		
		this._object2 = AGObject.createObject(this._model);
		this.addObject(this._object2);
		this._object2.setAction(1);
		this._object2.setPosition(new PointF(100,125));
		this._object2.setZIndex(998);

		this._object3 = AGObject.createObject(this._model);
		this.addObject(this._object3);
		this._object3.setAction(2);
		this._object3.setPosition(new PointF(100,225));
		this._object3.setZIndex(999);
		
		this._btnOK = new AGButton(new RectF(400,400, 600, 450), this._model);
		this.addControl(this._btnOK);
		this._btnOK.addClickEvent(new ButtonOKClick(this));

		this._btnSwitch = new AGButton(new RectF(400, 600, 600, 650), this._model);
		this.addControl(this._btnSwitch);
		this._btnSwitch.addClickEvent(new ButtonSwitchClick(this));
	}

	@Override
	public void onRender(AGContext context) {
		// TODO Auto-generated method stub
	}

	@Override
	public void onUpdate(AGContext context) {
		// TODO Auto-generated method stub
		
	}
	
	class ButtonOKClick implements IAGEventHandler{
		private TestView1 _view;
		public ButtonOKClick(TestView1 view){
			this._view = view;
		}
		
		@Override
		public void onHandle(AGControl control) {
			// TODO Auto-generated method stub
		}
	}
	
	class ButtonSwitchClick implements IAGEventHandler{
		private TestView1 _view;
		public ButtonSwitchClick(TestView1 view){
			this._view = view;
		}
		
		@Override
		public void onHandle(AGControl control) {
			// TODO Auto-generated method stub
			this._view.switchView(new TestView2());
		}
	}
	
	class AnimationCompleted implements IAGAnimationCompletedEventHandler{

		private TestView1 _view;
		public AnimationCompleted(TestView1 view){
			this._view = view;
		}
		
		@Override
		public void completed(AGAnimation animation) {
			// TODO Auto-generated method stub
			this._view._object2.setPosition(new PointF(100, 50));
			this._view._btnOK.setVisible(true);
		}
	}
}